<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>ECSHOP 管理中心 - <?php echo ($meta_title); ?> </title>
    <meta name="robots" content="noindex, nofollow">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="/Public/css/general.css" rel="stylesheet" type="text/css"/>
    <link href="/Public/css/main.css" rel="stylesheet" type="text/css"/>
    <script src="/Public/js/jquery-1.11.3.js"></script>

    
    <link rel="stylesheet" type="text/css" href="/Public/ext/zTree/css/zTreeStyle/zTreeStyle.css" />

    
        <!--引入ztree-->
        <script src="/Public/ext/zTree/js/jquery.ztree.core.js"></script>
        <!--引入ztree复选框--> 
        <script type="text/javascript" src="/Public/ext/zTree/js/jquery.ztree.excheck.min.js"></script>
    <script>
       $(function(){
           //=======================使用ztree展示权限列表========================
            var setting = {
                //复选框
                check:{
                    enable:true,
                },
                
                data: {
                    simpleData: {
                        enable: true,
                        pIdKey:'parent_id',
                    }
                },
                
                callback:{
                    onCheck:function(){
                        //获取所有的被选中的选项
                        var checked_nodes = ztree_obj.getCheckedNodes(true);
                        //清除所有的隐藏域的值
                        perms_node.empty();
                        $(checked_nodes).each(function(){
                            //获取到半勾选状态的input
                            var half_check = this.getCheckStatus();
                            if(!half_check.half){
                                var html = '<input type="hidden" name="perm[]" value="' + this.id + '"/>';
                                $(html).appendTo(perms_node);
                            }
                        })
                    }
                }
            };

                      var zNodes = <?php echo ($permission); ?>;
                      var ztree_obj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
                      ztree_obj.expandAll(true);
                      var perms_node = $('#perms');
            
            //=================编辑回显======================
            <?php if(!empty($rows)): ?>var perms = <?php echo ($rows['permission_ids']); ?>;
            for(i in perms){
                var node = ztree_obj.getNodeByParam("id",perms[i]);
                ztree_obj.checkNode(node,true);
                var half_check = node.getCheckStatus();
                //将半选状态的选项忽略
                if(!half_check.half){
                    var html = '<input type="hidden" name="perm[]" value="' + perms[i] + '"/>';
                    $(html).appendTo(perms_node);
                }
            }<?php endif; ?>
       });
    </script>

</head>
<body>

    <h1>
        <span class="action-span1"><a href="<?php echo U('index');?>">角色管理</a></span>
        <span id="search_id" class="action-span1"> - <?php echo ($meta_title); ?> </span>
        <div style="clear:both"></div>
    </h1>
    <div class="main-div">
        <form method="post" action="<?php echo U();?>"enctype="multipart/form-data" >
            <table cellspacing="1" cellpadding="3" width="100%">
                <tr>
                    <td class="label">角色名称</td>
                    <td>
                        <input type="text" name="name" maxlength="60" value="<?php echo ($rows["name"]); ?>" />
                        <span class="require-field">*</span>
                    </td>
                </tr>
                <tr>
                    <td class="label">关联权限</td>
                    <td>
                        <div id="perms"></div>
                    <ul id="treeDemo" class="ztree"></ul>
                    </td>
                </tr>
                <tr>
                    <td class="label">角色描述</td>
                    <td>
                        <textarea  name="intro" cols="60" rows="4"   ><?php echo ($rows["name"]); ?></textarea>
                    </td>
                </tr>
                <tr>
                    <td class="label">排序</td>
                    <td>
                        <input type="text" name="sort" maxlength="40" size="15" value="<?php echo ($rows["sort"]); ?>" />
                    </td>
                </tr>
                <tr>
                    <td class="label">是否显示</td>
                    <td>
                        <input type="radio" name="status" value="1" checked="checked" /> 是
                        <input type="radio" name="status" value="0"  /> 否
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center"><br />
                        <input type="hidden" name='id' value="<?php echo ($rows["id"]); ?>" />
                        <input type="submit" class="button" value=" 确定 " />
                        <input type="reset" class="button" value=" 重置 " />
                    </td>
                </tr>
            </table>
        </form>
    </div>

<div id="footer">
    共执行 <?php echo N('db_query');?> 个查询，用时 <?php echo G('loadTime','initTime');?> 秒，Gzip 已禁用，内存占用 <?php echo number_format((memory_get_usage() - $GLOBALS['_startUseMems'])/1024);?> KB<br/>
    版权所有 &copy; 重庆京西商城，并保留所有权利。
</div>
</body>
</html>